<!-- 顶部计数 -->

<template>
  <div class="EnergyOverview-TopCount">
    <EasyCard v-for="(item, i) in dataList" :key="i" noScroll quar full>
      <div class="flex1 flexCC">
        <img :src="item[0]" />
      </div>

      <div class="flex3">
        <div>
          <b>{{ item[1] }}</b>
          <span>{{ item[2] }}</span>
        </div>

        <span>今日{{ item[3] }}</span>
      </div>

      <template #footer>
        <div class="flex6">
          <div>
            <span>本月{{ item[3] }}</span>
            <b>{{ item[4] }}</b>
            <span> {{ item[2] }}</span>
          </div>
        </div>

        <div class="flex1" />

        <div>
          <span>同比</span>
          <span v-if="item[5] > 0" class="Count-up"><img :src="CORE.common('up.png')" /> {{ item[5] }}%</span>
          <span v-else class="Count-down"><img :src="CORE.common('down.png')" /> {{ -item[5] }}%</span>
        </div>

        <div class="flex1" />

        <div>
          <span>环比</span>
          <span v-if="item[6] > 0" class="Count-up"><img :src="CORE.common('up.png')" /> {{ item[6] }}%</span>
          <span v-else class="Count-down"><img :src="CORE.common('down.png')" /> {{ -item[6] }}%</span>
        </div>
      </template>
    </EasyCard>
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import store from './store'

const getImg = (name) => CORE.common(`energy/${name}.png`)

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'TopCount',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixStore(store), CORE.mixLoop()],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('../components', true, /vue$/)),

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 数据列表
     */
    dataList() {
      const { electric: elec, water, gas, charcoal: carbon } = this.info

      return [
        [getImg('elec'), elec.today, 'kw·h', '用电量', elec.month, elec.yearOnYear, elec.monthOnMonth],
        [getImg('water'), water.today, 't', '用水量', water.month, water.yearOnYear, water.monthOnMonth],
        [getImg('gas'), gas.today, 'm³', '用气量', gas.month, gas.yearOnYear, gas.monthOnMonth],
        [getImg('carbon'), carbon.today, 't', '碳排放', carbon.month, carbon.yearOnYear, carbon.monthOnMonth],
      ]
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
